<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Filter</title>
	<!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
</head>
<body>
<script>
	//Filter 用于将某些元素给过滤掉
	//filter() 把传入的函数作用于每个元素，根据结果为true/false来决定是否保留
	let arr = [1,2,3,4,5,6,7,8,10];
	let result = arr.filter(x => x % 2 !== 0);
	console.log(result);
	console.log(arr);

	//删除arr中的空字符
	let arr1 = ['A','B','',null,undefined,'  ',' ','C'];
	let arr1Result = arr1.filter(x => x && x.trim());
	console.log(arr1Result);

	//回调函数
	let arr2 = ['A','B','C'];
	let arr2Result = arr2.filter(function (element,index,self) {
		console.log(element);
		console.log(index);
		console.log(self)
		return true;
	})
	console.log(arr2Result);


</script>
</body>
</html>